package com.peng.test.jdk;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ListSample
 *
 * @author lupeng
 * Created on 2022-04-30
 */
public class ListSample {

    private static final Logger logger = LoggerFactory.getLogger(ListSample.class);

    @Test
    public void s1() {
        List<String> list = new ArrayList<>();
        List<String> list1 = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(String.valueOf(i));
            list1.add(String.valueOf(i));
        }

        list.clear();
        list.addAll(list1);
        System.out.println(list);
    }

    @Test
    public void s2() {
        LinkedHashSet<String> linkedHashSet = new LinkedHashSet<>();
        linkedHashSet.add("999");
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            list.add(String.valueOf(i));
        }
        linkedHashSet.clear();
        linkedHashSet.addAll(list.subList(0, 10));
        System.out.println(linkedHashSet);
    }

    @Test
    public void s3() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");

        for (int i = 0; i < 100; i++) {
            Collections.shuffle(list);
            System.out.println(StringUtils.equals(list.get(0), list.get(1)));
            System.out.println(list);
        }
    }

}
